/*
 *  Copyright 2008 Danny Lagrouw
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 */
package org.bastion.domain;


/**
 * Abstract super class for entity objects with an ID field, that
 * are automatically registered with the domain upon creation. It
 * is not necessary to extend domain classes from AbstractEntity;
 * this is merely a convenience class for domain classes that have
 * an ID field and must be registered.
 */
public abstract class AbstractEntity {

	private Long id;
	
	protected AbstractEntity() {
		Long id = Domain.register(this);
		if (id != null) {
			this.id = id;
		}
	}
	
	/**
	 * Trick to prevent persisters from looping eternally while
	 * internally creating objects.
	 * 
	 * @param b
	 */
	protected AbstractEntity(boolean b) {}
	
	public Long getId() {
		return id;
	}
	
}
